//package com.retail.global.log;
//
//import cn.hutool.core.util.ObjectUtil;
//import com.retail.core.enums.DelFlagEnum;
//import com.retail.core.enums.StatusFlagEnum;
//import com.retail.core.result.Result;
//import com.retail.global.annon.OrderTraceLog;
//import com.retail.global.security.LoginUserUtil;
//import com.retail.mall.entity.request.OrderLogRequest;
//import com.retail.mall.entity.vo.OrderVo;
//import com.retail.mall.service.OrderLogService;
//import com.retail.mall.service.OrderService;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.annotation.After;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint;
//import org.springframework.stereotype.Component;
//
//import java.util.Arrays;
//import java.util.stream.Collectors;
//
///**
// * @author Administrator
// */
//@Aspect
//@Component
//@Slf4j
//public class OrderTraceLogSupport {
//
//    private final OrderLogService orderLogService;
//
//    private final OrderService orderService;
//
//    public OrderTraceLogSupport(OrderLogService orderLogService, OrderService orderService) {
//        this.orderLogService = orderLogService;
//        this.orderService = orderService;
//    }
//
//    @Pointcut("@annotation(com.retail.global.annon.OrderTraceLog)")
//    private void pointcut() {
//    }
//
//    @After("pointcut()&&@annotation(orderTraceLog)")
//    public void after(JoinPoint joinPoint, OrderTraceLog orderTraceLog) throws Throwable {
//        OrderLogRequest orderLogRequest = new OrderLogRequest();
//        String args = convertArgs(joinPoint.getArgs());
//        orderLogRequest.setArgs(args);
////        Result result = (Result)(joinPoint.);
//        Result result = (Result)((MethodInvocationProceedingJoinPoint) joinPoint).proceed();
//        Long orderId = (Long) result.getData();
//
//        String msg = result.getMessage();
//        if (ObjectUtil.isNotEmpty(orderId)) {
//            OrderVo orderVo = orderService.getModel(orderId);
//            orderLogRequest.setOrderData(orderVo.toString());
//            orderLogRequest.setOrderId(orderId);
//        }
//        orderLogRequest.setOrderLogMsg(msg);
//        String method = joinPoint.getSignature().toLongString();
//        orderLogRequest.setOrderLogMethod(method);
//        orderLogRequest.setStatusFlag(StatusFlagEnum.USE.getValue());
//        orderLogRequest.setDelFlag(DelFlagEnum.NO.getValue());
//        orderLogRequest.setCreateUser(LoginUserUtil.getUserId());
////        OrderVo orderVo = orderService.getModel()
//        orderLogService.save(orderLogRequest);
//
//        System.out.println(":after.........");
//    }
//
//    private String convertArgs(Object[] args)  {
//        if (ObjectUtil.isEmpty(args) || args.length == 0 ) {
//            return "";
//        }
//        return Arrays.stream(args).map(ar -> ar.toString()).collect(Collectors.joining(","));
//    }
//
//
//    /**
//     * 环绕通知：
//     *   环绕通知非常强大，可以决定目标方法是否执行，什么时候执行，执行时是否需要替换方法参数，执行完毕是否需要替换返回值。
//     *   环绕通知第一个参数必须是org.aspectj.lang.ProceedingJoinPoint类型
//     */
////    @Around(value = "pointcut()")
////    public Object doAroundAdvice(ProceedingJoinPoint proceedingJoinPoint){
////
//////        logger.info("环绕通知的目标方法名："+proceedingJoinPoint.getSignature().getName());
////        try {
////            Object obj = proceedingJoinPoint.proceed();
////            return obj;
////        } catch (Throwable throwable) {
////            throwable.printStackTrace();
////        }
////        return null;
////    }
//}
